package com.aiwu

import com.aiwu.library.abs.AbsStateManager
import com.aiwu.utils.CitraUtil
import java.text.DecimalFormat

/**
 * 即时存档
 */
class StateManager private constructor() : AbsStateManager() {
    override fun stateFileNameRegex(): String {
        return "${MyApp.getRunningGameId()}${STATE_VERSION_TAG}\\.([0-9]+)\\.cst"
    }

    override fun getStateDir(): String = CitraUtil.getStateDir()

    override fun getStateFileName(id: Int): String {
        val decimalFormat = DecimalFormat("00")
        val slot = decimalFormat.format(id.toLong())
        return "${MyApp.getRunningGameId()}${STATE_VERSION_TAG}.${slot}.cst"
    }

    override fun getStatePicFileName(id: Int): String {
        return "${MyApp.getRunningGameId()}${STATE_VERSION_TAG}_${id}.png"
    }

    companion object {
        //tip 存档版本,要同步修改core/savestate.cpp里面的命名
        private const val STATE_VERSION = 2000
        const val STATE_VERSION_TAG = "_version_$STATE_VERSION"
        val instance: StateManager by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) {
            StateManager()
        }
    }
}
